package com.leetcode.LC;

import java.util.HashMap;

public class LC1394 {
    public int findLucky(int[] arr) {

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i : arr) {
            if (map.containsKey(i)) {
                map.put(i, map.get(i) + 1);
            } else {
                map.put(i, 1);
            }
        }
        int k=-1;
        for (Integer integer : map.keySet()) {
            if (integer == map.get(integer)) {
                k=Math.max(k,integer);
            }
        }
        return k;
    }

    public static void main(String[] args) {
        System.out.println(new LC1394().findLucky(new int[]{2, 2, 5, 3, 3}));
    }
}
